<template>
  <div class="post_manage">
    <div class="main">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane :label="'在线中的职位'+'('+statusonline+')'" name="1">
          <!-- <el-tab-pane :label="'在线中的职位'" name="1"> -->
          <div class="operation">
            <div>
              <el-button @click="refresTime()" type="primary">刷新职位</el-button>
              <el-button @click="offlineJob()" type="primary">下线</el-button>
              <el-button @click="deleteJob()">删除</el-button>
            </div>
            <div>
              <!-- <router-link to='/Release?type=1'> -->
              <div>
                <el-button type="primary" @click="post">发布职位</el-button>
              </div>
              <!-- </router-link> -->
            </div>
          </div>
          <el-table ref="multipleTable" :data="joblist" tooltip-effect="dark" style="width:100%;"
            @selection-change="handleSelectionChange" class="elTable">
            <el-table-column type="selection" width="55">
            </el-table-column>
            <el-table-column label="职位名称" prop="name" width="90" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="workAreaText" label="招聘地区" width="120" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="createTime" label="发布时间" width="150">
            </el-table-column>
            <el-table-column label="刷新时间" prop="refreshTime" width="150">
            </el-table-column>
            <el-table-column prop="expireTime" label="到期时间" width="150">
            </el-table-column>
            <el-table-column prop="exposureNum" label="曝光量" width="80">
              <template slot-scope="scope">
                <span>{{scope.row.exposureNum && scope.row.exposureNum > 9999 ? scope.row.exposureNum + '+' : scope.row.exposureNum}}</span>&nbsp;
              </template>
            </el-table-column>
            <el-table-column prop="browseNum" label="浏览量" width="65">
              <template slot-scope="scope">
                <span>{{scope.row.browseNum && scope.row.browseNum > 9999 ? scope.row.browseNum + '+' : scope.row.browseNum}}</span>&nbsp;
              </template>
            </el-table-column>
            <el-table-column prop="resumeDeliver" label="投递人数">
              <template slot-scope="scope">
                <span>{{scope.row.resumeDeliver && scope.row.resumeDeliver > 9999 ? scope.row.resumeDeliver + '+' : scope.row.resumeDeliver}}</span>&nbsp;
              </template>
            </el-table-column>
            <el-table-column label="操作" width="205">
              <template slot-scope="scope">
                <el-button type="text" size="small" @click="handleMore(scope.$index, scope.row)">搜人才</el-button>
                <el-button type="text" size="small" @click="handlerefresh(scope.$index, scope.row)">刷新</el-button>
                <el-button type="text" size="small" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
                <el-button type="text" size="small" @click="handleoffline(scope.$index, scope.row)">下线</el-button>
                <el-button type="text" size="small" @click="handleDelete(scope.$index, scope.row)" class="del">删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="pagination">
            <el-pagination background layout="prev, pager, next, total" :current-page="currentPage" :total="total"
              @current-change="current_change">
            </el-pagination>
          </div>
        </el-tab-pane>
        <el-tab-pane :label="'已下线职位'+'('+statusInsertingcoil+')'" name="3">
          <!-- <el-tab-pane :label="'已下线职位'" name="3"> -->
          <div class="operation">
            <div>
              <el-button @click="recoveryJob()" type="primary">恢复</el-button>
              <el-button @click="deleteJob()">删除</el-button>
            </div>
            <div>
              <div>
                <el-button type="primary" @click="post">发布职位</el-button>
              </div>
            </div>
          </div>
          <el-table ref="multipleTable" :data="joblist" tooltip-effect="dark" style="width: 100%"
            @selection-change="handleSelectionChange" class="elTable">
            <el-table-column type="selection" width="55">
            </el-table-column>
            <el-table-column label="职位名称" width="140" prop="name">
            </el-table-column>
            <el-table-column prop="workAreaText" label="招聘地区" width="160">
            </el-table-column>
            <el-table-column prop="createTime" label="发布时间" width="150">
            </el-table-column>
            <el-table-column prop="refreshTime" label="下线时间" width="150">
            </el-table-column>
            <el-table-column prop="exposureNum" label="曝光量">
              <template slot-scope="scope">
                <span>{{scope.row.exposureNum && scope.row.exposureNum > 9999 ? scope.row.exposureNum + '+' : scope.row.exposureNum}}</span>&nbsp;
              </template>
            </el-table-column>
            <el-table-column prop="browseNum" label="浏览量">
              <template slot-scope="scope">
                <span>{{scope.row.browseNum && scope.row.browseNum > 9999 ? scope.row.browseNum + '+' : scope.row.browseNum}}</span>&nbsp;
              </template>
            </el-table-column>
            <el-table-column prop="resumeDeliver" label="投递人数">
              <template slot-scope="scope">
                <span>{{scope.row.resumeDeliver && scope.row.resumeDeliver > 99 ? scope.row.resumeDeliver + '+' : scope.row.resumeDeliver}}</span>&nbsp;
              </template>
            </el-table-column>
            <el-table-column label="操作" width="180">
              <template slot-scope="scope">
                <el-button type="text" size="small" @click="handleMore(scope.$index, scope.row)">搜人才</el-button>
                <el-button type="text" size="small" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
                <el-button type="text" size="small" @click="handlerecovery(scope.$index, scope.row)">恢复</el-button>
                <el-button type="text" size="small" @click="handleDelete(scope.$index, scope.row)" class="del">删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="pagination">
            <el-pagination background layout="prev, pager, next, total" :current-page="currentPage" :total="total"
              @current-change="current_change">
            </el-pagination>
          </div>
        </el-tab-pane>
        <el-tab-pane :label="'审核中职位'+'('+statusExamine+')'" name="0">
          <!-- <el-tab-pane :label="'审核中职位'" name="0"> -->
          <div class="operation">
            <div>
              <el-button @click="deleteJob()">删除</el-button>
            </div>
            <div>
              <div>
                <el-button type="primary" @click="post">发布职位</el-button>
              </div>
            </div>
          </div>
          <el-table ref="multipleTable" :data="joblist" tooltip-effect="dark" style="width: 100%"
            @selection-change="handleSelectionChange" class="elTable">
            <el-table-column type="selection" width="55">
            </el-table-column>
            <el-table-column label="职位名称" width="140" prop="name">
            </el-table-column>
            <el-table-column prop="workAreaText" label="招聘地区">
            </el-table-column>
            <el-table-column prop="createTime" label="发布时间">
            </el-table-column>
            <el-table-column label="操作" width="130">
              <template slot-scope="scope">
                <el-button type="text" size="small" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
                <el-button type="text" size="small" @click="handleDelete(scope.$index, scope.row)" class="del">删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="pagination">
            <el-pagination background layout="prev, pager, next, total" :current-page="currentPage" :total="total"
              @current-change="current_change">
            </el-pagination>
          </div>
        </el-tab-pane>
        <el-tab-pane :label="'未通过职位'+'('+statusFail+')'" name="2">
          <!-- <el-tab-pane :label="'未通过职位'" name="2"> -->
          <div class="operation">
            <div>
              <el-button @click="deleteJob()">删除</el-button>
            </div>
            <div>
              <!-- <router-link to='/Release?type=1'>
                <el-button type="primary">发布职位</el-button>
              </router-link> -->
              <div>
                <el-button type="primary" @click="post">发布职位</el-button>
              </div>
            </div>
          </div>
          <el-table ref="multipleTable" :data="joblist" tooltip-effect="dark" style="width: 100%"
            @selection-change="handleSelectionChange" class="elTable">
            <el-table-column type="selection" width="55">
            </el-table-column>
            <el-table-column label="职位名称" width="140" prop="name">
            </el-table-column>
            <el-table-column prop="workAreaText" label="招聘地区" width="160">
            </el-table-column>
            <el-table-column prop="createTime" label="发布时间">
            </el-table-column>
            <el-table-column prop="failReason" label="未通过原因" show-overflow-tooltip>
            </el-table-column>
            <el-table-column label="操作" width="130">
              <template slot-scope="scope">
                <el-button type="text" size="small" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
                <el-button type="text" size="small" @click="handleDelete(scope.$index, scope.row)" class="del">删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="pagination">
            <el-pagination background layout="prev, pager, next, total" :current-page="currentPage" :total="total"
              @current-change="current_change">
            </el-pagination>
          </div>
        </el-tab-pane>
      </el-tabs>

    </div>
  </div>
</template>

<script>
import { refreshJob, list, deleteJob, offlineJob, recoveryJob, statusCount, validCompany } from '../../../api/index';
export default {
  data () {
    return {
      activeName: '1',
      id: '1',
      pagesize: 10,
      // 在线中的职位总数
      total: 0,
      joblist: [],
      multipleSelection: [],
      currentPage: 1,
      refreshTime: "",
      expireTime: '',
      currentIndex: 0,
      statusonline: '',//在招职位数量
      statusInsertingcoil: '',//已下线职位数量
      statusExamine: "",//审核中的职位数量
      statusFail: '',//未通过职位数量
    };
  },
  mounted () {
    this.getdata()
    this.statusCount()
  },
  methods: {
    handleClick (tab, event) {
      this.currentIndex = tab.index;
      // tab切换时让分页初始化
      this.currentPage = 1;
      this.getdata()
    },
    handleSelectionChange (val) {
      this.multipleSelection = val;
    },
    refresTime () {
      if (this.multipleSelection.length < 1) {
        this.$message.error('请选择需要刷新的职位!');
      } else {
        let file = new FormData();
        file.append('id', this.multipleSelection.map(item => item.id).join(','));
        refreshJob(file).then(data => {
          console.log(data);
          if (data.success) {
            this.getdata();
            this.$message.success('刷新成功');
          } else {
            this.$message.error(`${data.msg}`);
          }
        });
      }
    },
    offlineJob () {
      if (this.multipleSelection.length < 1) {
        this.$message.error('请选择需要下线的职位!');
      } else {
        let file = new FormData();
        file.append('id', this.multipleSelection.map(item => item.id).join(','));
        offlineJob(file).then(data => {
          console.log(data);
          if (data.success) {
            this.getdata();
            this.$message.success('下线成功');
          } else {
            this.$message.error(`${data.msg}`);
          }
        });
      }
    },
    deleteJob () {
      if (this.multipleSelection.length < 1) {
        this.$message.error('请选择需要删除的职位!');
        return false;
      } else {
        this.$confirm('将删除选中的职位, 是否确定删除?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let file = new FormData();
          file.append('id', this.multipleSelection.map(item => item.id).join(','));
          deleteJob(file).then(data => {
            console.log(data);
            if (data.success) {
              this.getdata();
              this.$message.success('删除成功');
            } else {
              this.$message.error(`${data.msg}`);
            }
          });
        }).catch(() => { });
      }
    },
    recoveryJob () {
      if (this.multipleSelection.length < 1) {
        this.$message.error('请选择需要恢复的职位!');
      } else {
        let file = new FormData();
        file.append('id', this.multipleSelection.map(item => item.id).join(','));
        recoveryJob(file).then(data => {
          console.log(data);
          if (data.success) {
            this.getdata();
            this.$message.success('恢复成功');
          } else {
            this.$message.error(`${data.msg}`);
          }
        });
      }
    },
    // 获取列表数据
    getdata () {
      //开启loading
      const loading = this.$loading({
        lock: true,
        text: '加载中',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.1)'
      });
      let con = [];
      let c = {};
      c.column = "status";
      c.type = "eq";
      c.value = parseInt(this.activeName);
      con.push(c);
      con.push({ "column": "include", "type": "", "value": "D,RDN,FR" })
      let query = new FormData()
      query.append('page', this.currentPage)
      query.append('size', this.pagesize)
      query.append('condition', JSON.stringify(con));
      list(query).then(res => {
        if (res.success) {
          this.joblist = res.data.records || []
          this.total = res.data.total
          loading.close()
        } else {
          loading.close()
          this.$message.error(`${res.msg}`)
        }

      }).catch(() => {
        loading.close();
      })
    },
    handlerefresh (index, row) {
      let file = new FormData();
      file.append('id', row.id);
      refreshJob(file).then(data => {
        console.log(data);
        if (data.success) {
          this.getdata();
          this.$message.success('刷新成功');
        } else {
          this.$message.error(`${data.msg}`);
        }
      });
    },
    handlerecovery (index, row) {
      let file = new FormData();
      file.append('id', row.id);
      recoveryJob(file).then(data => {
        console.log(data);
        if (data.success) {
          this.getdata();
          this.$message.success('恢复成功');
        } else {
          this.$message.error(`${data.msg}`);
        }
      });
    },
    handleoffline (index, row) {
      let file = new FormData();
      file.append('id', row.id);
      offlineJob(file).then(data => {
        console.log(data);
        if (data.success) {
          this.getdata();
          this.$message.success('下线成功');
        } else {
          this.$message.error(`${data.msg}`);
        }
      });
      // let query=new FormData()
      // query.append('id',row.id)
      // offlineJob(query).then(res=>{
      //     this.getdata()
      // })
    },
    handleEdit (index, row) {
      console.log(index, row, '我需要的');
      this.$router.push({
        path: '/Release',
        query: {
          row: JSON.stringify(row),
          type: 2
        }
      })
    },
    handleDelete (index, row) {
      this.$confirm('将删除该职位, 是否确定删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let file = new FormData();
        file.append('id', row.id);
        deleteJob(file).then(data => {
          console.log(data);
          if (data.success) {
            this.$message.success('删除成功');
            this.getdata();
          } else {
            this.$message.error(`${data.msg}`);
          }
        });
      }).catch(() => { });
    },
    current_change (currentPage) {
      this.currentPage = currentPage;
      this.getdata()
    },
    //获取数量
    statusCount () {
      // let query = new FormData()
      // query.append('status', '0,1,2,3')
      statusCount().then(res => {
        if (res.success) {
          this.statusonline = res.data.status1
          this.statusInsertingcoil = res.data.status3
          this.statusExamine = res.data.status0
          this.statusFail = res.data.status2
        } else {

          this.$message.error(`${res.msg}`)
        }
      })
    },
    // 搜更多人才
    handleMore (index, row) {
      this.$router.push({
        path: '/TalentPool'
      })
    },
    post () {
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });
      validCompany().then(res => {
        if (res.success) {
          loading.close()
          this.$router.push({
            path: '/Release?type=1'
          });
        } else {
          loading.close()
          this.$alert(res.msg, '系统提醒', {
            confirmButtonText: '完善信息',
            callback: action => {
              this.$router.push({
                path: '/companySet'
              })
            }
          });
        }
      })
    }
  },
};
</script>
<style lang="css" scoped>
.post_manage {
    /* margin-top: 30px; */
    width: 100%;
}
.post_manage .main {
    background: #fff;
    width: 1200px;
    margin: 0 auto;
    padding: 30px;
    box-sizing: border-box;
}
.el-pagination {
    background: #fff !important;
}
.nav_title {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.tit_text {
    font-size: 14px;
}
.operation {
    width: 100%;
    height: 45px;
    display: flex;
    justify-content: space-between;
}
.elTable {
    width: 100%;
    height: 530px;
    border-bottom: 0;
    font-size: 14px;
}
.elTable .del {
    color: #fd4e40;
}
.el-table /deep/ th,
.el-table /deep/ td {
    text-align: center;
}
.el-table__body-wrapper .el-table__empty-block {
    width: 99.8% !important;
    height: 488px !important;
    border-bottom: 0;
}
.el-table__body-wrapper .el-table__empty-text {
    font-size: 18px;
}
.pagination {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    height: 124px;
    text-align: center;
    background: #ffffff;
}
</style>
